package comparable;


public class Student implements Comparable<Student>{

    private int id;
    private String name;

    public Student(int id,String name){
        this.id = id;
        this.name = name;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    //排序优先级id-name
    @Override
    public int compareTo(Student c) {
        if (this.id != c.id) {
            return this.id < c.id ? 1 : -1;
        }else{
            if (this.name.equals(c.name)) {
                return 0;
            }
            return this.name.compareTo(c.name) > 0 ? 1 : -1;
        }
    }

    @Override
    public String toString() {
        return "Student [id=" + id + ", name=" + name +"]";
    }
}
